/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.modules.admin.dto.BuildingUserContractDTO;
import org.springblade.modules.admin.dto.PlanCheckStatisticsQueryDTO;
import org.springblade.modules.admin.dto.ProjectDTO;
import org.springblade.modules.admin.dto.TlwBuildingElevatorQuery;
import org.springblade.modules.admin.dto.building.BuildingUserElevatorDTO;
import org.springblade.modules.admin.dto.platform.BuildingSearchDTO;
import org.springblade.modules.admin.dto.sugar.SugarSearchDTO;
import org.springblade.modules.admin.dto.sugar.rescue.SugarRescueSearchDTO;
import org.springblade.modules.admin.entity.Building;
import org.springblade.modules.admin.entity.BuildingExt;
import org.springblade.modules.admin.entity.BuildingUserContract;
import org.springblade.modules.admin.entity.RelationAlias;
import org.springblade.modules.admin.vo.*;
import org.springblade.modules.admin.vo.building.BuildingUserElevatorDetailVo;
import org.springblade.modules.admin.vo.building.BuildingUserElevatorVo;
import org.springblade.modules.admin.vo.building.BuildingUserStatusVo;
import org.springblade.modules.admin.vo.erp.service.BuildingMessageVO;
import org.springblade.modules.admin.vo.feishu.GalaxyMaintainCustomerVO;
import org.springblade.modules.admin.vo.openapi.SidaBuildingBasicVO;
import org.springblade.modules.admin.vo.platform.BuildingSumVo;
import org.springblade.modules.admin.vo.platform.BuildingVo;
import org.springblade.modules.admin.vo.rescue.map.MapRescueBuildingDetailVO;
import org.springblade.modules.admin.vo.sugar.PieChartVO;
import org.springblade.modules.admin.vo.sugar.ProjectOverviewVO;
import org.springblade.modules.admin.vo.sugar.bi.BILarkGroupSourceVO;
import org.springblade.modules.admin.vo.sugar.bi.BILarkRescueAreaResourceVO;
import org.springblade.modules.admin.vo.sugar.bi.BILarkRescueBigTableVO;
import org.springblade.modules.admin.vo.sugar.bi.BILarkRescueBuildingSourceVO;
import org.springblade.modules.admin.vo.sugar.map.SugarMapEleBuildVo;
import org.springblade.modules.admin.vo.tlw.TlwBuildingVO;
import org.springblade.modules.admin.vo.tlw.TlwElevatorEstateUserVO;
import org.springblade.modules.admin.vo.tlw.TlwElevatorVO;
import org.springblade.modules.system.entity.User;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 楼盘信息 服务类
 *
 * @author BladeX
 * @since 2021-05-11
 */
public interface BuildingService extends BaseService<Building> {

	/**
	 * 小区类型字典码
	 */
	String PROJECT_TYPE_CODE = "building_type";

    /**
     * 自定义分页
     *
     * @param page
     * @param building
     * @return
     */
    IPage<BuildingVO> selectBuildingPage(IPage<BuildingVO> page, Building building);


    BuildingVO selectBuilding(Long id);


	/**
	 * 批量查询
	 * @param ids
	 * @return
	 */
	List<BuildingVO> selectBuildingByIds(List<Long> ids);

    List<BuildingVO> buildingVOList();

    /**
     * 根据buildingId查询物业人员信息
     *
     * @param buildingId
     * @return
     */
    List<EstateUserInfoVO> selectEstateUserInfoByBuildingId(Long buildingId);

	IPage<ProjectVO> selectProjectPage(IPage<ProjectVO> page, Building building);

	/**
	 * 项目新增/编辑
	 * @param project
	 * @return
	 */
	Long projectSaveOrEdit(ProjectDTO project);

	/**
	 * 获取区域下拉框数据
	 * @return
	 */
	List<String> getALlCityNameList();

	/**
	 * 根据市获取镇区下拉框数据
	 * @param cityName
	 * @return
	 */
	List<String> getALlAdNameList(String cityName);


	/**
	 * 根据项目id获取维护的人员列表
	 * @param id
	 * @return
	 */
	List<User> getUserListById(Long id);

	/**
	 * 获取电梯列表包括电梯数量
	 * @param sugarSearchDTO 查询条件
	 * @return 数据集
	 */
    List<Building> getList(SugarSearchDTO sugarSearchDTO);

	/**
	 * 获取小区树形结构
	 * @return 数据集
	 */
	List<BuildingTreeVo> treeList();


	/**
	 * 平台公共项目管理,分页列表
	 * @param page 分页信息
	 * @param building 查询条件
	 * @return 数据集
	 */
    IPage<BuildingVo> selectBuildingPageV2(IPage<BuildingVo> page, BuildingSearchDTO building);


	/**
	 * 获取项目汇总信息
	 * @return 数据集
	 */
	BuildingSumVo getBuildingSumInfo();

	/**
	 * 获取项目下拉列表
	 * @return
	 */
	BuildingSelectListStatisticsVO buildingSelectList();

	/**
	 * 梯联网-获取项目下拉列表（忽略租户）
	 * @return
	 */
	List<BuildingSelectListVO> buildingTlwSelectList(PlanConfigSearchVO search);

	/**
	 * 大屏-维保项目-即将到期项目
	 * @return
	 */
	PieChartVO comingExpiryProject();

	/**
	 * 大屏-维保项目-即将到期项目-总体项目分布情况
	 * @return
	 * @param queryDTO
	 */
	PieChartVO projectElevator(PlanCheckStatisticsQueryDTO queryDTO);

	/**
	 * 大屏-维保项目-项目总览
	 * @return
	 */
	ProjectOverviewVO projectOverview();

	/**
	 * 梯联网物业公司统计
	 */
	Integer estateBuildingCountStatistics();

	/**
	 * 梯联网排行榜
	 * @param deviceList
	 * @return
	 */
	List<TlwRankingListVO> rankingList(List<String> deviceList);

	/**
	 * 获取当前物业下的项目信息
	 * @param building
	 * @return
	 */
    List<Building> getListByBuilding(Building building);

	/**
	 * 不区分租户查询
	 * @param buildingId 项目id
	 * @return 数据集
	 */
	Building selectById(Long buildingId);

    Map<String, Object> tlwBuildingElevatorCount(TlwBuildingElevatorQuery tbeQuery);

	IPage<TlwBuildingVO> selectTlwBuildingElevatorPage(TlwBuildingElevatorQuery tbeQuery, IPage<TlwBuildingVO> page);

	/**
	 * 获取项目下拉列表
	 * @param search
	 * @return
	 */
	List<BuildingVO> selectSearchList(BuildingVO search);

	List<TlwBuildingVO> selectTlwBuilding(List<Long> ids);

	List<TlwElevatorVO> selectTlwElevator(List<Long> elevatorIds);

    List<TlwElevatorEstateUserVO> selectTlwEstateElevatorUser(Long userId);

	/**
	 * 获取缓存所需列表信息
	 * @return 缓存所需VO
	 */
	List<BuildingRedisVO> listForVO();

	/**
	 * 缓存更新
	 */
	void addRedisBuilding();

	BuildingExt selectBuildingExtDetail(Long buildingId);

    MapRescueBuildingDetailVO selectMapRescueBuildingDetail(Long buildingId);

	/**
	 * 救援大屏 根据 building
	 * @return building VO
	 */
	List<BuildingRescueScreenVO> getRescueScreenB(SugarRescueSearchDTO searchDTO);

	/**
	 * 困人救援高发电梯 top 10
	 * @return elevator VO
	 */
	List<ElevatorRescueScreenVO> getRescueScreenE(SugarRescueSearchDTO searchDTO);

	/**
	 * 困人救援高发场所列表
	 * @return 高发场所列表，VO复用项目，但实际代表的是场所
	 */
	List<BuildingRescueScreenVO> getRescueScreenT(SugarRescueSearchDTO searchDTO);

	/**
	 * 困人救援人员 top 10
	 * @param beginTime 开始时间
	 * @param endTime 结束时间
	 * @param sort 1：根据次数倒序 2：根据超时排序 3：根据平均时长排序
	 * @return 人 VO 列表
	 */
    List<UserRescueScreenVO> getRescueScreenU(Date beginTime, Date endTime, Integer sort);


	/**
	 * 新维修大屏当前租户项目-电梯统计
	 * @return 统计VO
	 */
    BuildingElevatorCountVO getBuildingElevatorCounts();


	/**
	 * 获取维修大屏地图项目和电梯信息
	 * @return 数据集
	 * @param searchDTO
	 */
	SugarMapEleBuildVo getSugarMapEleBuildInfo(SugarSearchDTO searchDTO);

	/**
	 * 初始化驻点
	 * @return 驻点值
	 */
    boolean stagnationInit();

    List<BuildingESVO> listForEsInit();

	/**
	 * 更新项目别名
	 * @param relationAliases
	 * @param building
	 * @return
	 */
	boolean addRelationAliases(List<RelationAlias> relationAliases, Building building);

	/**
	 * 获取银河维保客户信息
	 * @return 银河维保客户信息VO
	 */
	List<GalaxyMaintainCustomerVO> getGalaxyMaintainCustomerList();

	List<SidaBuildingBasicVO> getBuildingListByTenantId(String tenantId);

    List<BiBuildingVO> listBiBuildingList();


	/**
	 * 伙伴云ERP查询银河租户项目
	 * @return 银河租户项目信息
	 */
    List<BuildingMessageVO> selectBuildingMessageList();

	/**
	 * 伙伴云ERP查询银河租户项目
	 * @return 银河租户项目信息
	 */
	List<BuildingMessageVO> selectBuildingMessageListByBuildingId(Long buildingId);

	List<BILarkRescueBigTableVO> getLarkRescueBigTable(Date startDate, Date endDate);

    List<BILarkRescueBigTableVO> getLarkRescueBigTableByCondition(Date startDate, Date endDate);

	List<BILarkGroupSourceVO> getLarkGroupSourceByCondition(Date startDate, Date endDate);

	List<BILarkRescueBuildingSourceVO> getLarkRescueBuildingSourceByCondition(Date startDate, Date endDate);

	List<BILarkRescueAreaResourceVO> getLarkRescueAreaResourceByCondition(Date startDate, Date endDate);

	List<BILarkRescueAreaResourceVO> getLarkRescueAreaPlaceByCondition(Date startDate, Date endDate);

    List<Building> listByH3Index();

    Building getByBuildingNameAndGroup(String buildingName, String groupId);

	List<Long> getBuildingIdsByGroupId(String groupId);


	/**
	 * 获取项目的合同统计
	 * @param buildingId 项目id
	 * @return 数据集
	 */
    BuildingUserStatusVo getBuildingStatus(Long buildingId);

	/**
	 * 项目列表分页
	 * @param buildingUserContractDTO 查询条件
	 * @return 数据集
	 */
	IPage<BuildingUserContract> buildDingListV2(BuildingUserContractDTO buildingUserContractDTO);


	/**
	 * 项目-电梯的统计统计
	 * @param buildingId 项目id
	 * @param timeType 1:开启 0 不开
	 * @return 数据集
	 */
	BuildingUserElevatorVo elevatorStatus(Long buildingId, Integer timeType);


	/**
	 * 项目-电梯列表
	 * @param buildingUserElevatorDTO 搜索条件
	 * @return 数据集
	 */
	IPage<BuildingUserElevatorDetailVo> elevatorListV2(BuildingUserElevatorDTO buildingUserElevatorDTO);
}

